package com.zhuky.controller;

import java.util.concurrent.Future;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhuky.task.TestAsyncTask;

@Controller
@RequestMapping("/task")
public class TaskController {

	@Autowired
	private TestAsyncTask testAsyncTask;
	
	@RequestMapping("/test1")
	@ResponseBody
	public String test1() throws InterruptedException {
	
		long start = System.currentTimeMillis();
		
		Future<Boolean> doTask1 = testAsyncTask.doTask1();
		Future<Boolean> doTask2 = testAsyncTask.doTask2();
		Future<Boolean> doTask3 = testAsyncTask.doTask3();
		
		while(!doTask1.isDone()||!doTask2.isDone()||!doTask3.isDone()) {
			if(doTask1.isDone()&&doTask2.isDone()&&doTask3.isDone()) {
				break;
			}
		}
		long end = System.currentTimeMillis();
		String times = "任务全部完成，总耗时：" + (end - start) + "毫秒";
		System.out.println(times);
		return times;
	}
}
